package com.telit.firecommand.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.telit.common.exception.ForestBaseException;
import com.telit.firecommand.dao.CommSatelliteInfoDao;
import com.telit.firecommand.entity.CommSatelliteInfo;
import com.telit.firecommand.service.CommSatelliteInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class CommSatelliteInfoServiceImpl implements CommSatelliteInfoService {

    @Autowired
    private CommSatelliteInfoDao commSatelliteInfoDao;

    @Override
    public void add(CommSatelliteInfo commSatelliteInfo) {
        if(commSatelliteInfoDao.insert(commSatelliteInfo) < 0) {
            throw new ForestBaseException("新增卫星遥感设备失败");
        }
    }

    @Override
    public void deleteById(Integer id) {
        if(commSatelliteInfoDao.deleteByPrimaryKey(id) < 0) {
            throw new ForestBaseException("删除卫星遥感设备失败");
        }
    }

    @Override
    public void update(CommSatelliteInfo commSatelliteInfo) {
        if(commSatelliteInfoDao.updateByPrimaryKeySelective(commSatelliteInfo) < 0) {
            throw new ForestBaseException("新增卫星遥感设备失败");
        }
    }

    @Override
    public Object queryPageByCondition(Integer page, Integer rows) {
        if (rows == null || page == null) {
            page = 1;
            rows = 10;
        }
        IPage<CommSatelliteInfo> satePage = new Page<>(page, rows);
        return commSatelliteInfoDao.queryPageByCondition(satePage);
    }
}
